package com.n.common;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTemplate;

public abstract class BaseDao<T>{


    @Autowired
    protected HibernateTemplate ht;
    
    @Autowired
    protected JdbcTemplate jt;
    
    public void save(T t){
    	ht.save(t);
    }   
    
    public void merge(T t){
    	ht.merge(t);
    } 
    
    public void del(T t){
    	ht.delete(t);
    }
    
    protected void del(String tableName, Serializable id){
    	String sql = "delete from "+tableName+" where c_id="+id;
    	jt.execute(sql);
    }
    
    public T load(Class<T> t, Serializable id){
    	return ht.get(t, id);
    }
    
    public List<T> loadAll(Class<T> t){
    	/*String hql = "from "+t.getSimpleName();
    	System.out.println(hql);
    	return ht.find(hql);*/
    	return ht.loadAll(t);
    }
    
    public List<T> load(String hql){
    	return ht.find(hql);
    }
}
